#include "can_open.h"

static void BaseInfoGetValue_10000A01(can_receive_message_struct msg)
{
    g_lcd_display_info.pack_v = (uint16_t)((msg.rx_data[1] << 8) | msg.rx_data[0]);
    g_lcd_display_info.pack_c = (int32_t)((msg.rx_data[5] << 24) | (msg.rx_data[4] << 16) | (msg.rx_data[3] << 8) | msg.rx_data[2]);
    g_lcd_display_info.soc = (uint16_t)((msg.rx_data[7] << 8) | msg.rx_data[6]) / 10;
}

static void BaseInfoGetValue_10000A02(can_receive_message_struct msg)
{
    g_lcd_display_info.remain_cap = (uint16_t)((msg.rx_data[3] << 8) | msg.rx_data[2]) / 100;
    g_lcd_display_info.designed_cap = (uint16_t)((msg.rx_data[5] << 8) | msg.rx_data[4]) / 100;
    g_lcd_display_info.cycle_cnt = (uint16_t)((msg.rx_data[7] << 8) | msg.rx_data[6]);
}


void can_rx_iap_cmd(can_receive_message_struct msg)
{
    if (msg.rx_sfid == (uint32_t)0x00A0)
    {
        if ((msg.rx_data[0] == 0x11) 
         && (msg.rx_data[1] == gUart_Project_Name[0])
         && (msg.rx_data[2] == gUart_Project_Name[1])
         && (msg.rx_data[3] == gUart_Project_Name[3])
         && (msg.rx_data[4] == gUart_Project_Name[4])
         && (msg.rx_data[5] == gUart_Project_Name[5])
         && (msg.rx_data[6] == gUart_Project_Name[6])
         && (msg.rx_data[7] == gUart_Project_Name[8])) 
        {
            iap_flag = 1;
            return;
        }
    }
}

void can_recv_handle(can_receive_message_struct msg)
{
    switch (msg.rx_efid)
    {
    // 以下帧为基本参数
    case 0x10000A01:
        BaseInfoGetValue_10000A01(msg);
        break;

    case 0x10000A02:
        BaseInfoGetValue_10000A02(msg);
        break;

		case 0x10000A12:
			g_lcd_display_info.comm_state = CAN;
			g_lcd_manager.comm_disconnect_cnt = 0;
            g_lcd_manager.lcd_event = REFRESH_DATA;
			break;

		default:
			break;
	}
}	
